package edu.sctu.zcy.month201506.day20150619;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.*;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

import java.io.IOException;


/**
 * Created by user24 on 2015/6/19.
 */
public class HttpGet1 {


   HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();

    CloseableHttpClient closeableHttpClient = httpClientBuilder.build();


    public void sendGet(){

        HttpGet httpGet = new HttpGet("http://www.baidu.com");


        try {
            HttpResponse httpResponse = closeableHttpClient.execute(httpGet);
            HttpEntity httpEntity = httpResponse.getEntity();

            System.out.println("状态："+httpResponse.getStatusLine());

            if(httpEntity != null){
                System.out.println("contentEncoding:" + httpEntity.getContentEncoding());
                System.out.println("response content:" + EntityUtils.toString(httpEntity));
            }

            closeableHttpClient.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


}
